//
//  HomeHDCell.m
//  jingdongfang
//
//  Created by LJL on 2018/5/7.
//  Copyright © 2018年 BOE. All rights reserved.
//

#import "HomeHDCell.h"

@interface HomeHDCell ()
{
    UIImageView *imgView;
    UIImageView *tras;
    UIImageView *icon;
    UILabel *user;
    UILabel *name;
}

@end

@implementation HomeHDCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor c3Color];
        [self loadUI];
    }
    return self;
}

- (void)loadUI
{
    imgView = [[UIImageView alloc] initWithFrame:CGRectZero];
    imgView.contentMode = UIViewContentModeScaleAspectFill;
    imgView.layer.cornerRadius = 5;
    imgView.layer.masksToBounds = YES;
    [self.contentView addSubview:imgView];
    
    tras = [[UIImageView alloc] initWithFrame:CGRectZero];
    UIImage *image = [UIImage imageNamed:@"B-16-2"];
    [image stretchableImageWithLeftCapWidth:4 topCapHeight:2];
    tras.image = image;
    [imgView addSubview:tras];
    
    icon = [[UIImageView alloc] initWithFrame:CGRectZero];
    icon.image = [UIImage imageNamed:@"home_look"];
    [tras addSubview:icon];
    
    user = [[UILabel alloc] initWithFrame:CGRectZero];
    user.textColor = [UIColor c3Color];
    user.textAlignment = NSTextAlignmentLeft;
    user.font = [UIFont font10];
    [tras addSubview:user];
    
    name = [[UILabel alloc] initWithFrame:CGRectZero];
    name.textColor = [UIColor c4Color];
    name.numberOfLines = 0;
    name.textAlignment = NSTextAlignmentLeft;
    name.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:name];
    
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-37.5);
    }];
    
    [tras mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(22);
    }];
    
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.centerY.mas_equalTo(tras);
    }];
    
    [user mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(icon).offset(25);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(15);
        make.centerY.mas_equalTo(tras);
    }];
    
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(35);
        make.left.right.bottom.mas_equalTo(0);
    }];
//    user.text = @"999";
//    name.text = @"最美的时光遇见你:情人节";
}

- (void)setHdModel:(IGDrawModel *)hdModel
{
    if (_hdModel != hdModel)
    {
        user.text = hdModel.browseNum.length > 0 ? hdModel.browseNum : @"0";
        name.text = hdModel.title;
        [imgView sd_setImageWithURL:[NSURL URLWithString:hdModel.image] placeholderImage:[UIImage imageFromColor:[UIColor mainRandomColor]]];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if (_isBig)
    {
        imgView.layer.cornerRadius = 10;
        [name mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
        }];
    }
}

@end
